"""
Helper functions

Consists of functions to typically be used within templates, but also
available to Controllers. This module is available to both as 'h'.
"""
# Import helpers as desired, or define your own, ie:
# from webhelpers.html.tags import checkbox, password

# Some basic imports
from routes import url_for
from webhelpers.html import escape, HTML, literal, url_escape
from webhelpers.html.tags import *

# And a few more for extra things
from webhelpers.date import *
from webhelpers.text import *
from webhelpers.html.converters import *
from webhelpers.html.tools import *
from webhelpers.util import *

from pylons.controllers.util import redirect as redirect_to

class Flash(object):
    def set_message(self, message_text, message_type):
        session = self._get_session()
        session["flash.text"] = message_text
        session["flash.type"] = message_type
        session.save()

    def has_message(self):
        session = self._get_session()
        return "flash.text" in session

    def get_message_text(self):
        session = self._get_session()
        message_text = session.pop("flash.text", None)
        if not message_text:
            return None
        session.save()
        return message_text

    def get_message_type(self):
        session = self._get_session()
        message_type = session.pop("flash.type", None)
        if not message_type:
            return None
        session.save()
        return message_type

    def _get_session(self):
        from pylons import session
        return session

flash = Flash()
